package edu.com.wjt219971332.config;

import edu.com.wjt219971332.config.interceptor.MyInterceptor;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.http.converter.HttpMessageConverter;
import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter;
import org.springframework.web.servlet.config.annotation.*;

import java.util.List;


@Configuration
@ComponentScan({"edu.com.wjt219971332.controller", "edu.com.wjt219971332.config","edu.com.wjt219971332.dao"})
//将数据转化为json格式
@EnableWebMvc
public class WebMvcJavaConflg implements WebMvcConfigurer {
    //视图解析器，编写跳转界面的前缀和后缀
    @Override
    public void configureViewResolvers(ViewResolverRegistry registry) {
        registry.jsp("/WEB-INF/pages/", ".jsp");
    }
    //开启静态资源查找
    //dispatcherServlet
    @Override
    public void configureDefaultServletHandling(DefaultServletHandlerConfigurer configurer) {
        configurer.enable();
    }

    @Override
    public void configureMessageConverters(List<HttpMessageConverter<?>> converters) {
        converters.add(new MappingJackson2HttpMessageConverter());
    }
    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        //这种方式会拦截所有请求
        //registry.addInterceptor(new MyInterceptor());
        //这种方式会拦截指定的请求
//        registry.addInterceptor(new MyInterceptor()).addPathPatterns("/user/**");
    }

}
